Skip to content

Conversation

@christerswahn
Copy link
Collaborator

@christerswahn christerswahn commented Nov 12, 2025

To enable IP-based geotracking of the client origin, MixPanel requires the URI query parameter ip to be set to 1.

Summary by CodeRabbit

  • New Features

    • Added an option to disable IP tracking in analytics for enhanced privacy control.
  • Improvements

    • Analytics endpoint handling updated to correctly preserve existing query parameters when toggling IP tracking, improving reliability of analytics requests.

@coderabbitai
Copy link

coderabbitai bot commented Nov 12, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

MixPanelAnalytics constructor was changed: endpoint became nullable and disableIpTracking (bool) was added. Internal _endpoint moved from String to Uri, built via a new _buildEndpoint helper that preserves existing query params and toggles ip=0/ip=1. _quietPost now posts to the Uri.

Changes

Cohort / File(s) Summary
Analytics core
packages/cli_tools/lib/src/analytics/analytics.dart
- _endpoint type changed from String to Uri.
- Constructor signature: endpoint changed to nullable String?, added bool disableIpTracking = false.
- Added static Uri _buildEndpoint(String baseEndpoint, bool disableIpTracking) to parse the base URL, preserve existing query params, and set ip=0 or ip=1.
- _endpoint initialized via _buildEndpoint(endpoint ?? _defaultEndpoint, disableIpTracking).
- _quietPost updated to use the Uri _endpoint directly.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant MixPanelAnalytics
  participant HTTP

  Caller->>MixPanelAnalytics: new MixPanelAnalytics(..., endpoint?, disableIpTracking?)
  Note right of MixPanelAnalytics: constructor
  MixPanelAnalytics->>MixPanelAnalytics: _buildEndpoint(baseEndpoint, disableIpTracking)\n(parse, preserve queries, set ip=0/1)
  MixPanelAnalytics->>MixPanelAnalytics: store `_endpoint` as Uri

  Caller->>MixPanelAnalytics: trackEvent(...)
  MixPanelAnalytics->>MixPanelAnalytics: _quietPost(payload)
  MixPanelAnalytics->>HTTP: POST `_endpoint` with payload
  HTTP-->>MixPanelAnalytics: response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Areas to review closely:
    • packages/cli_tools/lib/src/analytics/analytics.dart_buildEndpoint parsing and query-preservation logic.
    • Call sites of MixPanelAnalytics to ensure nullable endpoint and disableIpTracking handling is correct.
    • Any tests referencing endpoint strings or expecting specific query parameters.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding IP geotracking capability to analytics through a new disableIpTracking parameter.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef3e8fd and 41e7926.

📒 Files selected for processing (1)
  • packages/cli_tools/lib/src/analytics/analytics.dart (2 hunks)

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/cli_tools/lib/src/analytics/analytics.dart (1)

34-34: Consider using positive boolean naming for clarity.

The parameter disableIpTracking uses negative naming, which can lead to double-negative logic (e.g., !disableIpTracking to check if enabled). Consider renaming to enableIpTracking with a default of true for improved readability.

If you prefer positive naming, apply this diff:

-    final bool disableIpTracking = false,
+    final bool enableIpTracking = true,
   })  : _uniqueUserId = uniqueUserId,
         _projectToken = projectToken,
         _version = version,
         _endpoint = (endpoint ?? _defaultEndpoint) +
-            (disableIpTracking ? '?ip=0' : '?ip=1'),
+            (enableIpTracking ? '?ip=1' : '?ip=0'),
         _timeout = timeout;

Note: This would need to be combined with the query string fix from the previous comment.

Also applies to: 38-39

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ed5c5f2 and ef3e8fd.

📒 Files selected for processing (1)
  • packages/cli_tools/lib/src/analytics/analytics.dart (1 hunks)

Copy link
Contributor

@SandPod SandPod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have any custom parameters in Serverpod, so the CodeRabbit issue is not critical for us.

Although it would probably be good to use that approach (uri.replace) to support any additional parameters.

@christerswahn christerswahn merged commit 902a5f6 into main Nov 12, 2025
9 of 10 checks passed
@christerswahn christerswahn deleted the ces-dev branch November 12, 2025 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants